from django.shortcuts import render, HttpResponse
from django.http.request import QueryDict
from django.views.decorators.http import require_http_methods


def index(request):
    # <class 'django.http.request.QueryDict'>
    # print(type(request.GET))
    # print(type(request.POST))

    # p = request.GET['p']
    # print(p)

    # 1.get方法：用来获取指定key的值，如果没有这个key，那么会返回None
    p = request.GET.get('p', default=1)
    print(p)
    return HttpResponse('success')


@require_http_methods(['GET', 'POST'])
def article(request):
    if request.method == 'GET':
        return render(request, 'article.html')
    title = request.POST.get('title')
    content = request.POST.get('content')
    # 2.getlist方法：如果浏览器上传上来的key对应的值有多个，那么就需要通过这个方法获取
    tags = request.POST.getlist('tags')
    print('title：', title)
    print('content：', content)
    print('tags：', tags)
    return HttpResponse('success')
